﻿<hi:common_vheader runat="server" />
<script src="http://res.juseshop.com/utility/vshopSelector/vshopSelector.js" type="text/javascript"></script>
<div id="divLogin" class="pbox" style="text-align:center; margin-top:50px;">

    <p>用户登录</p>
    <div>
        <input type="text" id="txtUserName" class="form-control" placeholder="请输入您的用户名" style="width:255px;text-align:center; display:inline-block;">
        <div>
            <!-- class="input-group"-->
            <input id="txtPassword" type="password" class="form-control" placeholder="请输入您的密码" style="width:255px;text-align:center; display:inline-block;">
            <span class="input-group-btn">
                <button style="display:none" class="btn btn-default" type="button" ontouchstart="javascript:$('#txtPassword').attr('type','text');" ontouchend="javascript:$('#txtPassword').attr('type','password');"><span class="glyphicon glyphicon-eye-open"></span></button>
            </span>
        </div>
        <button type="button" id="btnBindUser" class="btn btn-success btn-block" style="width:255px;display:inline-block;">确认绑定这个账号</button>
    </div>
    <p><a id="aRegister" style="margin-left:-20px;" href="javascript:void(0)">我还没有账号，立刻去注册！</a></p>
    <Hi:SiteUrl ID="SiteUrl21" UrlName="logout" runat="server">安全退出</Hi:SiteUrl>
</div>
<div id="divRegister" class="pbox" style="display:none;">
    <p>立即注册</p>
    <input type="url" id="txtRegisterUserName" class="form-control" placeholder="请输入您的用户名" onkeyup="$('#text_mail').val($(this).val());">
    <div class="input-group mail">
        <input id="text_mail" type="url" class="form-control" placeholder="请输入您的邮箱">
        <div id="emailList" class="input-group-btn"></div>
        <input type="hidden" id="text_email_domain" />
    </div>

    <div class="input-group">
        <input id="text_password" type="password" class="form-control" placeholder="请输入您的密码">
        <span class="input-group-btn">
            <button class="btn btn-default" type="button" ontouchstart="javascript:$('#text_password').attr('type','text');" ontouchend="javascript:$('#text_password').attr('type','password');"><span class="glyphicon glyphicon-eye-open"></span></button>
        </span>
    </div>

    <button type="button" id="btnRegisterUser" class="btn btn-danger btn-block">用户注册</button>

    <p class="text-right"><a id="aLogin" href="javascript:void(0)">我已有账号，立刻去登录！</a></p>
</div>
<script>
    //禁用右上角菜单
    document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
        WeixinJSBridge.call('hideOptionMenu');
    });
</script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#btnBindUser").bind("click", function () { BindUser(); }); //绑定商城账号
        $("#btnRegisterUser").bind("click", function () { RegisterUser(); }); //绑定商城账号
        $("#aRegister").bind("click", function () { $("#divLogin").hide(); $("#divRegister").show(); });
        $("#aLogin").bind("click", function () { $("#divLogin").show(); $("#divRegister").hide(); });

        var emails = [
          { text: '@qq.com', selected: true },
          { text: '@163.com' },
          { text: '@126.com' },
          { text: '@sina.com.cn' },
          { text: '@gmail.com' },
          { text: '@sohu.com' },
          { text: '@hotmail.com' },
          { type: 'divider' },
          { text: '手动输入', href: "javascript:$('.input-group.mail').after($('#text_mail'));$('.input-group.mail').remove();" }
        ];

        $('#emailList').vshopSelector({
            data: emails, height: '34',
            onchanged: function (item) {
                $('#text_email_domain').val(item.text);
            }
        });
        $('#emailList .btn-group').removeClass('btn-group').addClass('input-group-btn');

    });

    function BindUser() {

        var username = $.trim($("#txtUserName").val()),
           password = $.trim($("#txtPassword").val());

        if (!username || username.length < 2)
            alert_h('用户名不能为空并且至少要2个字符');
        else if (!password || password.length < 6)
            alert_h('密码不能为空并且至少要6个字符');
        else {


            $.ajax({
                url: "/API/VshopProcess.ashx",
                type: 'post', dataType: 'json', timeout: 10000,
                data: { action: "BindUser", openId: getParam("sessionId"), userName: username, password: password },
                success: function (resultData) {
                    if (resultData.Status == "OK") {
                        alert_h("登录成功！", function () {
                            var i = location.href.indexOf("returnUrl");
                            if (i > 0) {
                                location.href = location.href.substr(i + 10);
                            }
                            else {
                                location.href = "/Vshop/Default.aspx";
                            }
                        });
                    }
                    else if (resultData.Status == "-1") {
                        alert_h("用户名不存在, 请重试");
                    }
                    else if (resultData.Status == "2")
                        alert_h("您要绑定的用户已经被系统禁止登录");
                    else {
                        alert_h("用户名或密码错误, 请重试");
                    }
                }
            });
        }
    }

    function RegisterUser() {
        var username = $.trim($("#txtRegisterUserName").val()),
           email = $.trim($("#text_mail").val() + ($('.input-group.mail').length > 0 ? $('#text_email_domain').val() : '')),
           password = $.trim($("#text_password").val());

        var emailReg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
        if (!username || username.length < 2)
            alert_h('用户名不能为空并且至少要2个字符');
        else if (!email)
            alert_h('邮箱地址不能为空');
        else if (!emailReg.test(email)) {
            alert_h('邮箱地址格式不正确');
        }
        else if (!password || password.length < 6)
            alert_h('密码不能为空并且至少要6个字符');
        else {
            $.ajax({
                url: "/API/VshopProcess.ashx",
                type: 'post', dataType: 'json', timeout: 10000,
                data: { action: "RegisterUser", openId: getParam("sessionId"), userName: username, email: email, password: password },
                success: function (resultData) {
                    if (resultData.Status == "OK") {
                        alert_h("注册成功！", function () {
                            var i = location.href.indexOf("returnUrl");
                            if (i > 0) {
                                location.href = location.href.substr(i + 10);
                            }
                            else{
                                location.href = "/Vshop/Default.aspx";
                            }
                        });
                    }
                    else if (resultData.Status == "-1") {
                        alert_h("用户名已被注册过, 请重试");
                    }
                    else if (resultData.Status == "-2") {
                        alert_h("邮件已经被注册过, 请重试");
                    }
                    else {
                        alert_h("注册失败, 请重试");
                    }
                }
            });
        }
    }
</script>
<hi:common_vfooter runat="server" />

